<?php 
namespace app\dboard\logic;
use think\Db;
use think\facade\Session;
class System extends Base
{

    function __construct()
    {
    }
    public function edit($param)
    {
        $send_class_notice_time = isset($param['send_class_notice_time']) ? trim($param['send_class_notice_time']):'';
        $sid = isset($param['sid']) ? intval($param['sid']):0;
        if (!$sid) {
            $this->res_data['Msg'] = "缺少必填信息";
            return $this->res_data;
        }
        $store= Db::name('store')->where([['id','=',$sid]])->find();
        if (!$store) {
          $this->res_data['Msg'] = "无此门店";
          return $this->res_data;
        }
        $act= Db::name('system')->where([['sid','=',$sid]])->find();
        if (!$act) {
            $data['sid'] =$sid;
            $data['send_class_notice_time'] =$send_class_notice_time;
            $data['createtime'] = $data['updatetime'] = time();
            $is_insert = Db::name('system')->insertGetId($data);
            if(!$is_insert) {
                $this->res_data['Msg'] = '设置出错';
                return $this->res_data;
            }
        } else {
            $data['sid'] =$sid;
            $data['send_class_notice_time'] =$send_class_notice_time;
            $data['updatetime'] =time();
            $adata = Db::name('system')->where([['id','=',$act['id']]])->data($data)->update();
            if(!$adata) {
                $this->res_data['Msg'] = '设置出错';
                return $this->res_data;
            }
        }
        $this->res_data['Msg'] = '成功';
        $this->res_data['Code'] = 0;
        return $this->printResult($this->res_data);
    }

}

?>
